package com.bclz.baseLearn

import scala.collection.Seq
import scala.util.Random

object Test {

  def main(args: Array[String]) {

    var i = 1
    var list = List(1, 2, 3, 4)
    if (i == 1) {
      var k = (1 to 10)
      println("第一个元素:" + k.start)
    }
    for (j <- 1 to 10) {
      print(j + " ")
    }

    var a = for {
      m <- list
      if m != 1; if m < 4
    } yield m

    for (j <- list) yield j
    println("Hello World!!!")
    println("yield 结果:" + a)

    val x = Random.nextInt(5)
    x match {
      case 0 => println("Random: zero")
      case 1 => println("Random: one")
      case _ => println("Random: many")
    }

    var dd = init()
    lazy val res = init()
    println("lazy已加载")
    println("lazy结果:"+res)
    println("muliplier(1) value = " + multiplier(1))
    println("muliplier(2) value = " + multiplier(2))
    
    var test=(factor:Int)=>println(factor)
    test(1)
    
    //长参数
    mutiString("1","2")
    mutiString(Array("1","2"):_*)
    
    val nums=Seq(1,2,3)
    println()
    println("序列:"+nums)
    val newNums=(x:Int)=>x*2
    println("map操作转换为乘2:"+nums.map(newNums))
    println(nums map newNums)
    
    println((1).+(2))
    
    onceSeconds(()=>{println("Running...........")})
    
  }
  
  def onceSeconds(callback: ()=>Unit){
      
      while(true){
        
        callback()
        Thread sleep 1000
      }
      
   }
  
  def mutiString(s:String *)=for(s1<-s) print(s1)
  
  
  var factor = 3
  val multiplier = (i: Int) => {
    var factor = 5
    i * factor
  }

  def init(a:Int=3) = {
    //长时间操作
    println("执行init...")
    0
  }
  
  
  def primal(a:Int,b:Int)=a+b
  def kelihua(a:Int)(b:Int)=a+b

}
  
